package com.Liux.blog.service.impl;

import com.Liux.blog.dao.CommentsMapper;
import com.Liux.blog.entity.Comments;
import com.Liux.blog.entity.CommentsVo;
import com.Liux.blog.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class CommentsServiceImpl implements CommentsService {

    @Autowired
    private CommentsMapper commentsMapper;

    @Override
    public int createComments(Comments comments) {
        comments.setCreateTime(new Date());
        int i = commentsMapper.insert(comments);

        return i;
    }

    @Override
    public int deleteComments(String cid) {
        Example example = new Example(Comments.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("id",cid);
        int i = commentsMapper.deleteByExample(example);

        return i;
    }

    @Override
    public List<CommentsVo> getArticleComments(String articleId) {
        List<CommentsVo> comments = commentsMapper.getCommentsByArticleId(articleId);
        return comments;
    }

    @Override
    public List<Comments> getUserComments(String userId) {
        Example example = new Example(Comments.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("userId",userId);
        List<Comments> comments = commentsMapper.selectByExample(example);
        return comments;
    }
}
